//
//  UINavigationBar+BackgroundClolor.m
//  UserFrameWork
//
//  Created by Zs on 16/11/10.
//  Copyright © 2016年 Zs. All rights reserved.
//

#import "UINavigationBar+BackgroundClolor.h"
#import <objc/runtime.h>


@implementation UINavigationBar (BackgroundClolor)
static char overlayKey;

- (UIView *)overlay{
    return objc_getAssociatedObject(self,&overlayKey);
}
- (void)setOverlay:(UIView *)overlay{
    objc_setAssociatedObject(self, &overlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)lt_setBackgroundColor:(UIColor *)backgroundColor
{
    if (!self.overlay) {
        [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + 20)];
        self.overlay.userInteractionEnabled = NO;
        self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth;    // Should not set `UIViewAutoresizingFlexibleHeight`
        [[self.subviews firstObject] insertSubview:self.overlay atIndex:0];
    }
    self.overlay.backgroundColor = backgroundColor;
}


@end
